package gameos.android;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.badlogic.gdx.backends.android.AndroidApplication;

public class GameOS extends AndroidApplication {
	/** Called when the activity is first created. */
	gameos.core.GameOS game;
	View gameView;
	@Override
	public void onCreate (Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
	     requestWindowFeature(Window.FEATURE_NO_TITLE);
	        //getWindow().addFlags(6815872);
	        getWindow().addFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
	        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
	        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
	      
	        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
	                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
	        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

		
		// Create the layout
        RelativeLayout layout = new RelativeLayout(this);
        
        game = new gameos.core.GameOS();
        game.android = new AndroidFunctionImp(this);
        // Create the libgdx View
        gameView = initializeForView(game, false);

        // Add the libgdx view
        layout.addView(gameView);

        // Hook it all up
        setContentView(layout);
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

	    if(event.getAction() == KeyEvent.ACTION_DOWN)
	    {
	        switch(keyCode)
	        {
	        case KeyEvent.KEYCODE_BACK:	        	
	        	gameView.setFocusable(true);
	        	gameView.requestFocus();
	        	gameView.onKeyDown(keyCode, event);
	        	return true;
	        }
	    }

	    return super.onKeyDown(keyCode, event);
	}
}